package whlogger.launcher.loginfields.views.behavior;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JButton;
import whlogger.launcher.loginfields.views.repositories.BehaviorRepository;

/**
 *
 * @author d3rbastl3r
 */
public class LoginJButtonBehavior implements PropertyChangeListener{
	private JButton component = null;
	
	private BehaviorRepository behaviorRepository = null;
	
	public LoginJButtonBehavior(JButton component, BehaviorRepository repository){
		this.component = component;
		this.behaviorRepository = repository;
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent event){
		if(event.getPropertyName().equals(AbstractJTextFieldBehavior.PROPERTY_NAME_1)){
			System.out.println("TEST");
			if(!this.behaviorRepository.getNicknameBehavior().isActive()){
				this.component.setEnabled(false);
				return;
			}
			
			if(!this.behaviorRepository.getPasswordBehavior().isActive()){
				this.component.setEnabled(false);
				return;
			}
			
			this.component.setEnabled(true);
		}
	}
}
